﻿<?php
	include '../inc/conn.php';
	include '../sendmail.php';
	session_start();
	extract($_POST);
	extract($_GET);
	unset($_POST,$_GET);
	
	if(!isset($_SESSION['logname'])){
		die("<div>User Session is missing</div>");
	}
	
	if (isset($act))
	{
		if (empty($vContent) || empty($iStatus)){
			echo "<script>alert('Some content must be filled in data!!');</script>";
			die("Some content must be filled in data!");
		}
		if ($act == 'mod')
		{	
			date_default_timezone_set('Asia/Shanghai');
			$db = new mysql();
			$table = "daily_table";
			$condition = "id=".$id;
			$mod_content="daily_content=\"".htmlentities($vContent,ENT_QUOTES)."\", 
			status=\"".htmlentities($iStatus,ENT_QUOTES)."\"";

			$db->update($table, $mod_content, $condition);

			if($iStatus=="Open")
				$iStatus="<font color='red'>Open</font>";
			
			//SendMail("日报更新——".$_SESSION['logchnname'], $vContent."</br><b>状态:</b> ".$iStatus);
			$param = array(
				'aSync'=>'Yes',
				'title'=>"日报更新——".$_SESSION['logchnname'],
				'msg'=>$vContent."</br><b>状态:</b> ".$iStatus,
				'to'=>'T'
			);
			doAsyncMail($param);
			echo "<script>alert('Data changed!');window.opener.location.reload();window.close();</script>";
			$db->close();
		}
	}
	
	if (!isset($id))
	{
		echo "<script>alert('ID is empty!');</script>";
		die("ID is empty!");
	}
	$db = new mysql();
	$sql = "select * from daily_table where id=".$id;
	$db->query($sql);
	$num = $db->db_num_rows();
	if ($num == 0)
		die("No data was found!");
	$row = $db->fetch_assoc();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">-->
<link rel="stylesheet" href="/css/bootstrap.min.css">
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery-migrate.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor_lang/zh-cn.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<style>
<!--
.xheDialog label {
	display: inline;
}
.form-horizontal .control-label {
	width: 80px;
}
.form-horizontal .controls {
	margin-left: 20px;
}
-->
</style>
<title>修改日报</title>
</head>
<body class="background">
<div class="container white-background pagecontent">
<form action="mod_daily.php?id=<? echo $id; ?>&act=mod" method="post">
<div>
日报内容:<br />
<textarea name="vContent" rows="12" cols="80" class="xheditor {tools:'simple',skin:'default', upImgUrl:'upload.php?immediate=1'}" style="width:940px;height:280px;">
<?
	echo htmlspecialchars_decode($row['daily_content']);
?>
</textarea>
</div>
<div>
状态:<select name="iStatus" id="iStatus">
<? 
	if ($row['status'] == "Open") 
		echo '<option value="Open" selected="selected">Open</option>';
	else
		echo '<option value="Open">Open</option>';
		
	if ($row['status'] == "Tracking") 
		echo '<option value="Tracking" selected="selected">Tracking</option>';
	else
		echo '<option value="Tracking">Tracking</option>';
	
	if ($row['status'] == "Close") 
		echo '<option value="Close" selected="selected">Close</option>';
	else
		echo '<option value="Close">Close</option>';	
?>
</select>
</div>

<div><br /><input class="btn btn-success btn-primary" name="submit" value="提交" type="submit"><input class="btn btn-danger" name="reset" value="重置" type="reset"></div>
</form>
</div>
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.js"></script>
</body>
</html>
